﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TriganleTests.Question;

namespace TriganleTests.Answer
{
    class Sofia:ITriangle
    {
        public int InTriangle(MyPoint A, MyPoint B, MyPoint C, MyPoint test)
        {
            double Fa = 0.0, Fb = 0.0, Fc = 0.0;

            Fa = (double)((C.Y - B.Y) * A.X - (C.X - B.X) * A.Y + (B.Y * C.X - C.Y * B.X));

            Fb = (double)((C.Y - A.Y) * B.X - (C.X - A.X) * B.Y + (A.Y * C.X - C.Y * A.X));

            Fc = (double)((B.Y - A.Y) * C.X - (B.X - A.X) * C.Y + (A.Y * B.X - B.Y * A.X));

            if (Fa == 0.0 || Fb == 0.0 || Fc == 0.0) return -1;

            double Fa1 = 0.0, Fb1 = 0.0, Fc1 = 0.0;

            Fa1 = (double)((C.Y - B.Y) * A.X - (C.X - B.X) * A.Y + (B.Y * C.X - C.Y * B.X)) * (double)((C.Y - B.Y) * test.X - (C.X - B.X) * test.Y + (B.Y * C.X - C.Y * B.X));

            Fb1 = (double)((C.Y - A.Y) * B.X - (C.X - A.X) * B.Y + (A.Y * C.X - C.Y * A.X)) * (double)((C.Y - A.Y) * test.X - (C.X - A.X) * test.Y + (A.Y * C.X - C.Y * A.X));

            Fc1 = (double)((B.Y - A.Y) * C.X - (B.X - A.X) * C.Y + (A.Y * B.X - B.Y * A.X)) * (double)((B.Y - A.Y) * test.X - (B.X - A.X) * test.Y + (A.Y * B.X - B.Y * A.X));

            if (Fa1 >= 0.0 && Fb1 >= 0.0 && Fc1 >= 0.0) return 1;
            else return 0;

        }

       
    }
}
